package leetcode.dynamic;

public class Lc714 {


    public int maxProfit(int[] prices, int fee) {
        int n = prices.length;
        int[][] dp = new int[n][2]; //dp[i][0]表示第i天不持有股票的最大收益，dp[i][1]表示第i天持有股票的最大收益
        dp[0][0] = 0;
        dp[0][1] = - prices[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i-1][0], dp[i-1][1] + prices[i] - fee);
            dp[i][1] = Math.max(dp[i-1][1], dp[i-1][0] - prices[i]);
        }
        return dp[n - 1][0];
    }

    public static void main(String[] args) {
        Lc714 lc714 = new Lc714();

        int[] p = {1,3,7,5,10,3};
        int f = 3;
        System.out.println(lc714.maxProfit(p, f));


    }
}
